package test

object test4 {

  def main(args: Array[String]): Unit = {
    val array = Seq(1, 2, 3, 4, 5, 6, 7, 8, 9)

    getX(array.map(_.toString), Seq())

    println(us.length)
    val q = us.filter(_.head == "5").filter(_(1) == "7").filter(_(2) == "8").filter(_(3) == "4").filter(_(4) == "2")

    q.foreach(x=>println(x.mkString(",")))
    array.map { i =>

      val g = q.map(_ (i -1 ))
      val m = g.groupBy(x => x).map(x => x._1 -> x._2.length).maxBy(_._2)

      println(i, m, m._2.toDouble / g.length.toDouble)
    }

  }

  var us: Seq[Seq[String]] = Seq()
  val remove = Seq(
    Seq(1, 2, 3,4),
    Seq(1, 3, 4,5),
    Seq(2, 5, 6,7),
    Seq(5, 7, 8,9),
    Seq(5, 6, 8,1),
    Seq(3, 7, 8,2),
    Seq(2, 6, 7,3),
    Seq(1, 4, 6,8),
    Seq(3, 5, 9,4)
  ).map(_.map(_.toString))

  def getX(array: Seq[String], sort: Seq[String]): Unit = {
    if (array.nonEmpty) {
      val len = array.length
      val i = 9 - len
      val r = remove(i)

      array.foreach { x =>
        if (r.indexOf(x) == -1) {
          val s = sort :+ x
          getX(array.diff(s), s)
        }
      }
    } else {
    //  println(sort.mkString(","))
      us = us :+ sort
    }
  }

}
